package hansot.model.dao;

import hansot.to.CategoryTO;
import hansot.to.CommentTO;
import hansot.to.GradeTO;
import hansot.to.MenuGradeTO;
import hansot.to.MenuTO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class MenuDAO {
	private SqlMapClientTemplate sqlMap;

	private MenuDAO(SqlMapClientTemplate sqlMap) {
		this.sqlMap = sqlMap;
	}
	
	public MenuTO selectMenuById(String menuId) throws SQLException{
		return (MenuTO)sqlMap.queryForObject("selectMenuById", menuId);
	}
	
	public ArrayList<CommentTO> selectCommentByMenuId(String menuId) throws SQLException{
		return (ArrayList<CommentTO>) sqlMap.queryForList("selectCommentByMenuId",menuId);
	}
	public ArrayList<MenuTO> selectMenuByCategory(String categoryId) throws SQLException{
		return (ArrayList<MenuTO>)sqlMap.queryForList("selectMenuByCategory", categoryId);
	}
	public ArrayList<CategoryTO> selectCategory()throws SQLException{
		return (ArrayList<CategoryTO>)sqlMap.queryForList("selectCategory");
	}
	
	public void insertComment(CommentTO comm) throws SQLException{
		System.out.println(comm);
		sqlMap.insert("insertComment",comm);
	}

	public MenuGradeTO selectMenuGradeByMenuId(GradeTO gto) throws SQLException {
		return (MenuGradeTO) sqlMap.queryForObject("selectMenuGradeByMenuId",gto.getMenuId());
	}

	public void insertMenuTotalGrade(String menuId) throws SQLException{
		sqlMap.insert("insertMenuTotalGrade",menuId);
	}

	public void insertGrade(GradeTO gto) throws SQLException{
		sqlMap.insert("insertGrade",gto);
	}
	
	public int countGradeByMenuId(String menuId)throws SQLException{
		return (int) sqlMap.queryForObject("countGradeByMenuId",menuId);
	}
	
	public void updateMenuTotalGrade(MenuGradeTO mgto)throws SQLException{
		System.out.println(mgto);
		sqlMap.update("updateMenuTodalGrade",mgto);
	}
	
	public int getMenuTotalGrade(String menuId) throws SQLException{
		return (int) sqlMap.queryForObject("getMenuTotalGradeByMenuId",menuId);
	}
	
	public void updateMenuGradeByMenuId(MenuTO mto)throws SQLException{
		sqlMap.update("updateMenuGradeByMenuId",mto);
	}
}
